/*
error
ok

 */
#include <iostream>
#include <typeinfo>
using namespace std;
class Base{
	public:
		virtual ~Base(){}
};
class Derived: public Base{
	public:
		void f(){
			cout << "Derived f()" << endl;
		}
};
int  main(void){
	
	Base *pb, b;
	Derived *pd, d;
	pb = &b;
	/*
	 *语法上不报错： 具有父子关系 具有多态特性  
	 *该转换不合理 在运行期间完成转换 转换失败 c++认为不安全
	 * */
	pd = dynamic_cast<Derived *>(pb);
	if(pd) cout << "ok" << endl;
	else cout << "error" << endl;
	
	//pd = reinterpret_cast<Derived *>(pb);
	//pd = (Derived *)pb; //C风格强转 可以编译通过
	//pd->f(); //有问题 尽管有可能执行出结果 Derived f()
	
	pb = &d;  //向上造型
	pd = dynamic_cast<Derived *>(pb); //编译通过  也是合理转换
	if(pd) cout << "ok" << endl;
	else cout << "error" << endl;
	
	return 0;
}
